#include "GameMenu.h"

GameMenu::GameMenu(
	WINAPP*  a_app,
	WINFPS*  a_fps,
	WINTIME* a_time,
	D3DF*    a_d3d,
	DINF*    a_din,
	bool     a_renew)
{
	m_app  = a_app;
	m_fps  = a_fps;
	m_time = a_time;
	m_d3d  = a_d3d;
	m_din  = a_din;

	strcpy_s(m_name,32,"GameMenu");
	m_selfId = GAMEMENU;
	m_swapId = GAMEMENU;
	m_completed = false;
	m_renew = a_renew;
}

void GameMenu::init()
{
	m_d3d->createEffect(&m_effect,"effects/ambient.fx");
	m_d3d->setEffect(&m_effect);

	m_play.init(FRAMEWORKS_MEM_REG);
	m_play.initTexture("textures/play.png",TEX_C,V2D_ZERO,V2D_ONES,0);

	m_cred.init(FRAMEWORKS_MEM_REG);
	m_cred.initTexture("textures/cred.png",TEX_C,V2D_ZERO,V2D_ONES,0);

	m_quit.init(FRAMEWORKS_MEM_REG);
	m_quit.initTexture("textures/quit.png",TEX_C,V2D_ZERO,V2D_ONES,0);

	m_play.setTrn(V2DF(WINW/2,WINH/2)+V2DF(0,0));
	m_cred.setTrn(V2DF(WINW/2,WINH/2)+V2DF(0,64));
	m_quit.setTrn(V2DF(WINW/2,WINH/2)+V2DF(0,136));

	m_play.onIdle([&](){m_play.setScl(V2DF(1,1));});
	m_play.onHover([&](){m_play.setScl(V2DF(1.08f,1.08f));});
	m_play.onClick([&](){m_swapId=GAMEGALAXY;m_completed=true;});

	m_cred.onIdle([&](){m_cred.setScl(V2DF(1,1));});
	m_cred.onHover([&](){m_cred.setScl(V2DF(1.08f,1.08f));});
	m_cred.onClick([&](){m_swapId=GAMECREDIT;m_completed=true;});

	m_quit.onIdle([&](){m_quit.setScl(V2DF(1,1));});
	m_quit.onHover([&](){m_quit.setScl(V2DF(1.08f,1.08f));});
	m_quit.onClick([&](){m_swapId=GAMEQUIT;m_completed=true;});
}

void GameMenu::reset()
{

}

void GameMenu::release()
{

}

void GameMenu::input()
{
	m_din->acquire();

	m_play.input();
	m_cred.input();
	m_quit.input();
}

void GameMenu::update()
{
	m_play.update();
	m_cred.update();
	m_quit.update();
}

void GameMenu::draw()
{
	m_d3d->drawBegin();

	m_play.draw();
	m_cred.draw();
	m_quit.draw();

	m_d3d->drawText(m_name,V2D_ZERO,CL_RED);
	m_d3d->drawEnd();
}

void GameMenu::pre()
{
	m_fps->update();
	m_time->update();
}

void GameMenu::post()
{

}